#ifndef _FML_CONFIG_H_
#define _FML_CONFIG_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "cJSON.h"
#include "fml_ota.h"
#include "hal_flash.h"

#pragma pack(1)
typedef struct _DEV_INFO
{
    //config
    uint16_t dev_addr;
    uint8_t detect_action;
    uint8_t led_init_value;
    uint8_t relay_onoff_over_thres;
    uint8_t bat_threshold;
    //status
    uint8_t software_version[3];
    uint8_t dev_uuid[12];
    uint8_t socket_status;
    uint16_t power_threshold;
    uint16_t cur_power;
    uint8_t led_onoff;
    uint8_t led_brightness;
    uint8_t cur_soc;
    uint8_t power_type;
    uint8_t e_ink_type;
}DEV_INFO;
#pragma pack()

extern DEV_INFO g_dev_info;
extern cJSON *g_dev_info_json;

int32_t fml_config_init(void);
int32_t fml_config_json_to_devinfo(DEV_INFO *dev_info, cJSON *p_root);
cJSON *fml_config_devinfo_to_json(DEV_INFO *dev_info);
uint8_t *fml_config_to_json(DEV_INFO *dev_info, OTA_INFO *ota_info);
int32_t fml_config_from_json(const uint8_t *json_str, DEV_INFO *dev_info, OTA_INFO *ota_info);
int32_t fml_config_set_devaddr(uint16_t dev_addr);
int32_t fml_config_set_power_threshold(uint16_t power_threshold);
int32_t fml_config_set_detect_action(uint8_t detect_action);
int32_t fml_config_set_led_init_value(uint8_t led_init_value);
int32_t fml_config_set_bat_threshold(uint8_t bat_threshold);
int32_t fml_config_set_relay_onoff_over_thres(uint8_t onoff);

#endif
